//
//  LJAnimationItem.m
//  LJAnimationsDemo
//
//  Created by raymond on 17/1/5.
//  Copyright © 2017年 raymond. All rights reserved.
//

#import "LJAnimationItem.h"

@interface LJAnimationItem ()

@end

@implementation LJAnimationItem

+ (instancetype)itemWithName:(NSString *)name object:(id)object {
    LJAnimationItem *item = [[[self class] alloc] init];
    item.name = name;
    item.object = object;
    
    return item;
}

- (void)setName:(NSString *)name {
    _name = name.copy;
    _nameStr = [self createAttributeString];
}

- (void)setIndex:(NSInteger)index {
    _index = index;
    _nameStr = [self createAttributeString];
}

- (NSAttributedString *)createAttributeString {
    NSString *fullStirng = [NSString stringWithFormat:@"%02zd. %@", self.index, self.name];
    NSMutableAttributedString *richString = [[NSMutableAttributedString alloc] initWithString:fullStirng];
    {
        FontAttribute *fontAttribute = [FontAttribute new];
        fontAttribute.font           = [UIFont fontWithName:@"Heiti SC" size:16.f];
        fontAttribute.effectRange    = NSMakeRange(0, richString.length);
        [richString addStringAttribute:fontAttribute];
    }
    
    {
        FontAttribute *fontAttribute = [FontAttribute new];
        fontAttribute.font           = [UIFont fontWithName:@"GillSans-Italic" size:16.f];
        fontAttribute.effectRange    = NSMakeRange(0, 3);
        [richString addStringAttribute:fontAttribute];
    }
    
    {
        ForegroundColorAttribute *foregroundColorAttribute = [ForegroundColorAttribute new];
        foregroundColorAttribute.color                     = [[UIColor blackColor] colorWithAlphaComponent:0.65f];
        foregroundColorAttribute.effectRange               = NSMakeRange(0, richString.length);
        [richString addStringAttribute:foregroundColorAttribute];
    }
    
    {
        ForegroundColorAttribute *foregroundColorAttribute = [ForegroundColorAttribute new];
        foregroundColorAttribute.color                     = [[UIColor redColor] colorWithAlphaComponent:0.65f];
        foregroundColorAttribute.effectRange               = NSMakeRange(0, 3);
        [richString addStringAttribute:foregroundColorAttribute];
    }
    return richString;
}

@end
